<?php
session_start();
date_default_timezone_set("Asia/Chongqing");
include("common/connect.php");
include("common/common.php");

$opt = trim(CheckUrlParamNoDie("opt"));
$showtype = trim(CheckUrlParamNoDie("showtype"));
$shousuo = CheckUrlParamNoDie("shousuo");
$tag = CheckUrlParamNoDie("tag");
$id = CheckUrlParamNoDie("id");

if(isset($_POST["Site_Submit"]))
{
	$title = trim(GetPostParamStr("Site_Name"));
	$url = trim(GetPostParamStr("Site_Url"));
	$picurl = trim(GetPostParamStr("Site_Logo"));
	$trade = trim(GetPostParamStr("trade"));
	$see = trim(GetPostParamStr("see"));
	$zu = trim(GetPostParamStr("Site_zu"));
	$zulei = trim(GetPostParamStr("Site_zulei"));
	$judge = trim(GetPostParamStr("judge")); //判断网店地址是购物兔搜索，还是直指该淘宝地址  0,1
	if($judge == "")
		$judge = 0;
	if($trade == 0)
		$type = trim(GetPostParamStr("tradez_Tag"));
	if($trade == 1)
		$type = trim(GetPostParamStr("traded_Tag"));
	
	if( $id != "")
	{
		$sql2 = "update daohang set title='$title', url='$url', pic_url='$picurl', type='$type', see=$see, trade=$trade, zu=$zu, zulei=$zulei, judge=$judge where id=$id";
		mysql_query($sql2);
		if (mysql_affected_rows() == 1)
			echo "<script>window.history.go(-2);</script>";
	}else{
		$sql = "insert into daohang (title,url,pic_url,type,see,trade,zu,zulei,judge) values ('$title', '$url','$picurl', '$type', $see, $trade, $zu, $zulei,$judge)";
		mysql_query($sql);
		echo "<script>window.history.go(-2);</script>";
	}
}

if ($opt == "del" && $id != "")
{
	mysql_query("delete from daohang where id=$id");
	if (mysql_affected_rows() == 1)
		echo "<script>window.history.go(-1);</script>";
}else if ($opt == "checkok" && $id != "")
{
	mysql_query("update daohang set see=10 where id=$id");
	if (mysql_affected_rows() == 1)
		echo "<script>window.history.go(-1);</script>";
}else if ($opt == "checno" && $id != "")
{
	mysql_query("update daohang set see=0 where id=$id");
	if (mysql_affected_rows() == 1)
		echo "<script>window.history.go(-1);</script>";
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>设置</title>
<script language="javascript" src="../js/jquery.min.js"></script>
<style type="text/css">
body { font-size:12px;}
table,tr,th,td { margin:0; padding:0; color:#666;}
table { background:#09F;}
th { background:#BEF;}
th,td { padding:10px;}
tr { background:#fff;}
a { color:#00F;}
/***网站提交***/
.Unbound { background:#f2eeef; width:500px; padding:10px; position:absolute; top:10px; left:240px; font-size:12px;}
.Unbound .unss { background:#FFF; padding:10px; border:1px solid #999;}
.Unbound .sel { height:30px; border-bottom:1px solid #ddd;}
.Unbound .sel .Close a { float:right; text-indent:0; width:40px; display:inline-block;}
.Unbound .ted { overflow:hidden;}
.Unbound .ted .ted_tj { margin-top:10px;}
.Unbound .ted .ted_tj span { width:90px; text-align:right; display:block; float:left;}
.Unbound .ted .ted_tj .tedinp,.Unbound .ted .ted_tj textarea { height:22px; line-height:22px; border:1px solid #ddd; font-size:12px; padding:0 5px; color:#666; overflow:hidden;}
.Unbound .ted .ted_tj select.tedinp { padding:0;}
.Unbound .ted .ted_tj textarea { width:360px; height:70px; }
.Unbound .ted .sz_btn { margin:20px auto; width:133px; overflow:hidden;}
.Unbound .ted .sz_btn input { background:url(http://www.gouwutu.com/new/doc/img/sebtn.jpg) no-repeat; cursor:pointer; padding:0; color:#FFF; font-weight:bold; width:133px; height:45px; border:0;}
</style>
</head>
<body>
<div style="padding:10px;"><a href="http://123.gouwutu.com/index.php" target="_blank">点击打开站长联盟</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="?opt=edit"><font color="#FF0000">添加用户</font></a>
	<?php 
 		if($showtype == 'checkno'){
			echo '&nbsp;&nbsp;<a href="union.php">未审核</a>&nbsp;&nbsp;<a href="?showtype=checkno"><b>已审核</b></a>';
		}else{
			echo '&nbsp;&nbsp;<a href="union.php"><b>未审核</b></a>&nbsp;&nbsp;<a href="?showtype=checkno">已审核</a>';
		}
	?>
    &nbsp;&nbsp;&nbsp;&nbsp;<a href="?showtype=<?php echo $showtype; ?>&opt=wz" >全部网站</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="?showtype=<?php echo $showtype; ?>&opt=wd" >全部网店</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="?showtype=<?php echo $showtype; ?>&opt=img" >推荐查看</a>&nbsp;&nbsp;&nbsp;&nbsp;<select  class="tedinp" name="Site_Tag" id="Site_Tag" size="1">
          		<option value="1" selected='selected'>序列号</option>
          		<option value="2">名 称</option>
          		<option value="3">URL地址</option>
        	</select>&nbsp;&nbsp;
        	<input type="text" size="20" id="showtype" name="showtype" value="" style="width:200px;">&nbsp;&nbsp;
            <input type="button" value="查找" onclick="javascript:OnFind();">&nbsp;&nbsp;<a href="union.php">默认显示</a>
	</div>
<table cellpadding="10" cellspacing="1" border="0" width="100%" style="color:red">
	<tr>
    	<th>序号</th>
    	<th>名称</th>
        <th>URL</th>
        <th>logo地址</th>
        <th>站/店</th>
        <th>类型</th>
        <th>判断</th>
        <th>流量</th>
        <th>返还</th>
        <th>转化率</th>
        <th>显示</th>
        <th>组</th>
        <th>操作</th>
    </tr>
    <?php
    $limt= " LIMIT 30";
	$sql = "";
	if(!isset($showtype) || $showtype == '')
		$sql .= " where see=0";
	if($showtype == 'checkno')
		$sql .= " where see>0";		
	if($shousuo != "" && $tag == '1')
		$sql .= " and id=$shousuo";
	if($shousuo != "" && $tag == '2')
		$sql .= " and title='$shousuo'";
	if($shousuo != "" && $tag == '3')
		$sql .= " and url='$shousuo'";
	if($opt == 'wz')
		$sql .= " and trade=0";
	if($opt == 'wd')
		$sql .= " and trade=1";
	if($opt == 'img')
		$sql .= " and pic_url!=''";

	$sql = "select * from daohang".$sql.' order by id desc'.$limt;
	//echo $sql.'**********';
	$result = mysql_query($sql);
	$i = 0;
	while( $result && $row = mysql_fetch_assoc($result))
	{
	?>
    <tr align="center">
    	<td><?php echo $row["id"]; ?></td>
    	<td><?php echo $row["title"]; ?></td>
        <td><a href="<?php echo $row["url"]; ?>" target="_blank"><?php echo $row["url"]; ?></a></td>
        <td><img src="<?php echo $row["pic_url"]; ?>" width="100" height="45" alt="" /></td>
        <td><?php if($row["trade"] == 0) echo "网站"; else if($row["trade"] == 1) echo "网店" ?></td>
        <td><?php echo $row["type"]; ?></td>
        <td><?php echo $row["judge"]; ?></td>
        <td><?php echo $row["stem"]; ?></td>
        <td><?php echo $row["return"]; ?></td>
        <td>4%</td>
        <td><?php echo $row["see"]; ?></td>
        <td><?php echo $row["zu"]; ?></td>
        <td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="?opt=edit&id=<?php echo $row["id"]; ?>">编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;
        <?php
			if($showtype == "" || !isset($showtype)){
				echo "<a href='?opt=checkok&id=".$row["id"]."'>审核通过</a>&nbsp;&nbsp;&nbsp;&nbsp;";
			}else if($showtype == "checkno"){
				echo "<a href='?opt=checno&id=".$row["id"]."'>不通过</a>&nbsp;&nbsp;&nbsp;&nbsp;";
			}
		 ?>
         <a href="javascript:if(confirm('确实要删除吗?'))location='?opt=del&id=<?php echo $row["id"]; ?>'">删除</a>
    </tr>
    <?php } ?>
</table>
<?php 
if($opt == "edit")
{ 
	//$siid = "";
	$siname = "";
	$siurl = "";
	$silogo = "";
	$sitag = "";
	$sides = "";
	$sidse = "";
	$sidzu = "";
	$sidzulei = "";
	$sijudge = "";
	
	if( $id != "" )
	{
		$esql = "select * from daohang where id=$id limit 1";
		$eresult = mysql_query( $esql );
		if( $eresult && $row2 = mysql_fetch_assoc( $eresult ) )
		{
			//$siid = 
			$siname = $row2["title"];
			$siurl = $row2["url"];
			$silogo = $row2["pic_url"];
			$sitag = $row2["type"];
			$sides = $row2["descript"];
			$sidse = $row2["see"];
			$sidzu = $row2["zu"];
			$sidzulei = $row2["zulei"];
			$sijudge = $row2["judge"];
		}
	}
?>
<div style="display:block;" class="Unbound">
    <div class="unss">
        <div class="sel"><h2><span class="Close"><a href="union.php">关闭</a></span>编辑/添加</h2></div>
        <div class="ted">
            <form onsubmit="return sunbmintSS()" method="post" action="union.php?id=<?php echo $id; ?>">
                <div class="ted_tj"><span>名称：</span><input type="text" value="<?php echo $siname; ?>" name="Site_Name" id="Site_Name" maxlength="100" style="width:160px;" class="tedinp"></div>
                <div class="ted_tj"><span>站/店</span>
                <input type="radio" value="0" id="trade" onclick="tradeWZ();" name="trade" <?php if($trade == 0 || $trade == "") echo 'checked="checked"'; ?> >&nbsp;网站&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="radio" value="1" id="trade" onclick="tradeWD();" name="trade" <?php if($trade == 1) echo 'checked="checked"'; ?> >&nbsp;网店</div>
                <div class="ted_tj" id="WZ"><span>网站类型：</span><select size="1" id="tradez_Tag" name="tradez_Tag" class="tedinp">
                  <option value="<?php echo $sitag; ?>"><?php echo $sitag; ?></option>
                  <option value="视频">视频</option>
                  <option value="游戏">游戏</option>
                  <option value="小说">小说</option>
                  <option value="社交">社交</option>
                  <option value="音乐">音乐</option>
                  <option value="电脑">电脑</option>
                  <option value="旅游">旅游</option>
                  <option value="学习">学习</option>
                  <option value="女性">女性</option>
                  <option value="生活">生活</option>
                  <option value="其他">其他</option>
                </select>
                </div>
                <div class="ted_tj" id="WD" style="display:none;"><span>网店类型：</span><select size="1" id="traded_Tag" name="traded_Tag" class="tedinp">
                  <option value="<?php echo $sitag; ?>"><?php echo $sitag; ?></option>
                  <option value="服饰">服饰</option>
                  <option value="鞋帽">鞋帽</option>
                  <option value="箱包">箱包</option>
                  <option value="配饰">配饰</option>
                  <option value="数码">数码</option>
                  <option value="家电">家电</option>
                  <option value="美容">美容</option>
                  <option value="护发">护发</option>
                  <option value="生活">生活</option>
                  <option value="超市">超市</option>
                  <option value="母婴">母婴</option>
                  <option value="车饰">车饰</option>
                  <option value="运动">运动</option>
                  <option value="户外">户外</option>
                  <option value="文化">文化</option>
                  <option value="娱乐">娱乐</option>
                  <option value="家居">家居</option>
                  <option value="建材">建材</option>
                </select>
                </div>
                <div class="ted_tj"><span>类型组：</span><input type="text" value="<?php echo $sidzu; ?>" name="Site_zu" id="Site_zu" style="width:30px;">&nbsp;&nbsp;组排序：<input type="text" value="<?php echo $sidzulei ; ?>" name="Site_zulei" id="Site_zulei" style="width:30px;">&nbsp;&nbsp;网店地址判断0,1：<input type="text" value="<?php echo $sidzulei ; ?>" name="judge" id="judge" style="width:30px;"></div>
                <div class="ted_tj"><span>地址：</span><input type="text" value="<?php echo $siurl; ?>" name="Site_Url" id="Site_Url" maxlength="100" style="width:360px;" class="tedinp"></div>
                <div class="ted_tj"><span>LOGO：</span><input type="text" value="<?php echo $silogo; ?>" name="Site_Logo" id="Site_Logo" maxlength="100" style="width:360px;" class="tedinp"></div>
                <div class="ted_tj"><span>显示位置：</span><input type="text" value="<?php echo $sidse; ?>" name="see" id="see" maxlength="100" style="width:30px;" class="tedinp">&nbsp;&nbsp;<font>0，未审核；1、2...8，页面显示的位置；10，审核通过</font></div>
                <p class="sz_btn"><input type="submit" value="提 交" name="Site_Submit" id="Site_Submit"></p>
                <span><!-----奇怪的360 去掉设置就没有了------></span>
            </form>
        </div>
    </div>
</div>
<?php } ?>
</body>
</html>
<script type="text/javascript">
function OnFind()
{
	var site_tag = document.getElementById("Site_Tag").value;
	var input_tradeid = document.getElementById("showtype").value;
	window.location.href= "union.php?showtype=<?php echo $showtype; ?>&shousuo=" + input_tradeid + "&tag=" + site_tag ;
}
function tradeWZ()
{
	document.getElementById("WZ").style.display="block";
	document.getElementById("WD").style.display="none";
}
function tradeWD()
{
	document.getElementById("WZ").style.display="none";
	document.getElementById("WD").style.display="block";
}
function sunbmintSS()
{
	var sitename = document.getElementById("Site_Name").value;
	var tradeztag = document.getElementById("tradez_Tag").value;
	var tradedtag = document.getElementById("traded_Tag").value;
	var siteurl = document.getElementById("Site_Url").value;
	var see = document.getElementById("see").value;
	var zu = document.getElementById("Site_zu").value;
	var zulei = document.getElementById("Site_zulei").value;
	
	if(tradeztag == "" && tradedtag == "")
	{
		alert("类型为空");
		return false;
	}
	if(sitename == "" || siteurl == "" || see == "" || zu == "" || zulei == "")
	{
		alert("不能为空的");
		return false;
	}
	
	return true;
}
function sunbmintJG()
{
	
}
</script>
